package filmring

/**
 * Created by IntelliJ IDEA.
 * User: nbrooks
 * Date: 5/1/11
 * Time: 3:31 PM
 * To change this template use File | Settings | File Templates.
 */
class PopularityComparator implements Comparator<Movie>{
    int compare(Movie movie1, Movie movie2) {
        return ( returnAverage( movie1.ratings.asList() ) - returnAverage( movie2.ratings.asList() ) )
    }

    float returnAverage(List<Rating> ratingList) {
        if(ratingList?.size()!=0) {
            float sum=0;
            for(r in ratingList) {
                sum += r.rating
            }
            float average = sum/ratingList.size()
            return average
        }
        return 0.0;
    }
}
